package com.shop.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shop.entity.Business;
import com.shop.entity.User;
import com.shop.service.BusinessService;
import com.shop.service.UserService;

/**
 * Servlet implementation class BusinessRegister
 */
@WebServlet("/BusinessRegister")
public class BusinessRegister extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BusinessRegister() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    private BusinessService BusinessService = new BusinessService();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		String msg = "";
		// 获取 用户的用户名和密码
		Business business = new Business();
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String password2 = request.getParameter("password2");
		
		
		// 判断 用户的用户名和密码是否填写
		if (!username.equals("") && !password.equals("") && !password2.equals("") && password.equals(password2)) {
			business.setUsername(username);
			business.setPassword(password);
			business.setPassword(password2);
			BusinessService.addBusiness(business);
			request.setAttribute("msg", "注册成功,请登录");
			request.getRequestDispatcher("BusinessLogin.jsp").forward(request, response);
			return;
			
		}else{
			request.setAttribute("msg", "注册失败,请输入完整的信息或账号已经存在");
			request.getRequestDispatcher("BusinessRegister.jsp").forward(request, response);
			return;
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
